import { request,upload } from "@/utils/request";

/**
 * 微信小程序登录接口
 */
export function wxLogin(data){
	return request({
		url:'/sys/user/info/login',
		method:'POST',
		data:{
			...data,
			loginType:"WX"
		}
	});
}

export function register({phoneNumber,smsCode}){
	const store = require('@/store/index').default;
	const platform = uni.getSystemInfoSync().platform;
	uni.getProvider({
		service:"oauth",
		success: (res) => {
			if(~res.provider.indexOf('weixin')){
				uni.login({
					provider:"weixin",
					success: (loginRes) => {
						uni.getUserInfo({
							success: (resInfo) => {
								return request({
									url: '/sys/user/info/wx-register',
									method: 'POST',
									data:{
										phoneNumber,
										smsCode,
										jsCode:loginRes.code
									}
								});
							},
							fail: (res) => {}
						})
					},
					complete: (error) => {}
				})
			}
		},
		complete: (error) => {}
	})
}

export function uploadAvatar(path){
	return upload({
		url: '/sys/user/social/info/upload-avatar',
		name: 'avatar',
		filePath: path
	})
}